package com.jgp.glmeeting.controller;

import com.jgp.glmeeting.model.Arrangement;
import com.jgp.glmeeting.model.Participants;
import com.jgp.glmeeting.service.ArrangementService;
import com.jgp.glmeeting.service.ParticipantsService;
import com.jgp.sys.common.controller.JGPController;
import com.jgp.sys.ui.GridResult;
import com.jgp.sys.ui.Pager;
import com.jgp.sys.ui.Result;
import com.jgp.sys.ui.annotation.UIParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/glMeeting/arrangementApiController")
public class ArrangementApiController extends JGPController {
    @Autowired
    private ArrangementService arrangementService;
    @Autowired
    private ParticipantsService participantsService;

    /**
     * a
     * 查询处理人员安排的总的和分页
     */
    @RequestMapping("/queryArrangement")
    public Result queryArrangement(Arrangement a, @UIParam("pager") Pager pager) {
        List<Arrangement> lists = arrangementService.queryArrangement(a, pager);
        List<GridResult.Category> categories = new ArrayList<>();
        categories.add(new GridResult.Category("姓名", "participantsId", Participants.class, "name"));
        categories.add(new GridResult.Category("手机号", "mobilePhone"));
        categories.add(new GridResult.Category("计划日期", "planDate"));
        categories.add(new GridResult.Category("会议座次", "siteNo"));
        categories.add(new GridResult.Category("会议车次", "busNo"));
        categories.add(new GridResult.Category("酒店房间号", "roomNo"));
        categories.add(new GridResult.Category("就餐安排", "diningArrange"));


        return ajaxRe("gdata", categories, lists, pager);
    }


    /**
     * 添加人员安排
     */

    @RequestMapping("/addArrangement")
    public Result addArrangement(Arrangement a) {
        Participants p = participantsService.queryParticipantsBymobilePhone(a.getMobilePhone());

        if (p == null) {
            return ajaxRe(false);
        } else {
            a.setParticipantsId(p.getId());
            arrangementService.addArrangement(a);
            return ajaxRe(true);
        }
    }
    /**
     * 删除人员安排
     */
    @RequestMapping("/removeArrangement")
    public Result removeArrangement(String id){
       arrangementService.removeArrangement(id);
        return ajaxRe(true);
    }
}
